﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Moving03.Administrator
{
    public partial class WebForm18 : System.Web.UI.Page
    {
        DataClasses1DataContext context = new DataClasses1DataContext();
        int mavc = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated == false || User.Identity.IsAuthenticated == true && !User.IsInRole("Admin"))
            {
                Response.Redirect("../Default.aspx");
            }
            mavc = int.Parse(Request.QueryString["mavc"]);
            if (!IsPostBack)
            {
                LoadHoaDon(mavc);
            }
        }
    
        protected void LoadHoaDon(int mavc)
        {
            string s = "";
            var query = from ttvc in context.ThongTinVanChuyens
                        join lh in context.LoHangs on ttvc.Id_LoHang equals lh.Id_LoHang
                        join tt in context.TinhTrangVanChuyens on ttvc.TinhTrang equals tt.Id_TinhTrang
                        join user in context.aspnet_Users on ttvc.Id_User equals user.UserId
                        join noidi in context.NoiDis on ttvc.IdNoiDi equals noidi.Id_Noidi
                        join noiden in context.NoiDens on ttvc.IdNoiden equals noiden.Id_NoiDen
                        join qg in context.DanhSachQuocGias on noidi.Id_Quocgia equals qg.Id_MaQGia
                        where ttvc.Id_TTVC == mavc
                        select new
                        {
                            ttvc.Id_TTVC,
                            ttvc.Id_LoHang,
                            user.HoTen,
                            lh.Ten_lo_hang,
                            ttvc.NgayDat,
                            qg.TenQuocGia,
                            noiden.Id_Quocgia,
                            tt.TenTinhTrang,
                            ttvc.TinhTrang,
                            ttvc.TongTien
                        };
            var query2 = from ctttvc in context.ChiTietVanChuyens
                         where ctttvc.Id_TTVC == mavc
                         select ctttvc;
            foreach (var i in query)
            {
                var query1 = from qg in context.DanhSachQuocGias
                             where qg.Id_MaQGia == i.Id_Quocgia
                             select qg;
                
                s = "<tr>"
                     + "<td style='width: 194px; text-align: left; font-size: medium;'><b>Mã hoá đơn</b></td>"
                     + "<td style='width: 194px'>" + i.Id_LoHang + "</td>"
                 + "</tr>"
                 + "<tr>"
                     + "<td style='width: 194px; text-align: left; font-size: medium;'><b>Tên LH</b></td>"
                     + "<td style='width: 194px'>" + i.Ten_lo_hang + "</td>"
                 + "</tr>"
                 + "<tr>"
                     + "<td style='width: 194px; text-align: left; font-size: medium;'><b>Người gởi</b></td>"
                     + "<td style='width: 194px'>" + i.HoTen + "</td>"
                 + "</tr>"
                 + "<tr>"
                     + "<td style='width: 194px; text-align: left; font-size: medium;'><b>Nơi đi</b></td>"
                     + "<td style='width: 194px'>" + i.TenQuocGia + "</td>"
                 + "</tr>"
                 + "<tr>"
                     + "<td style='width: 194px; text-align: left; font-size: medium;'><b>Nơi đến</b></td>";
                foreach (var j in query1)
                    s += " <td style='width: 194px'>" + j.TenQuocGia + "</td>"
            + " </tr>"
            + " <tr>";
                foreach (var k in query2)
                {
                    s += "<td style='width: 194px; text-align: left; font-size: medium;'><b>Phí gởi</b></td>"
                    + "<td style='width: 194px'>" + k.TienGoi + "  VNĐ" + "</td></tr>";

                    s += "<tr><td style='width: 194px; text-align: left; font-size: medium;'><b>Phí ký gởi</b></td>"
                    + "<td style='width: 194px'>" + k.TienKiGoi + "  VNĐ" + "</td></tr>";

                    s += "<tr><td style='width: 194px; text-align: left; font-size: medium;'><b>Phí chịu tác động</b></td>"
                    + "<td style='width: 194px'>" + k.TienChiuTacDong + "  VNĐ" + "</td></tr>";
                }
                 s+= "<td style='width: 194px; text-align: left; font-size: medium;'><b>Tổng tiền phí chuyển</b></td>"
                 + "<td style='width: 194px'>" + i.TongTien + "  VNĐ" + "</td>"
             + "</tr>"
            + " <tr>"
                 + "<td style='width: 194px; text-align: left; font-size: medium;'><b>Ngày đặt</b></td>"
                + " <td style='width: 194px'>" + i.NgayDat + "</td>"
             + "</tr>";
            }
            dynamic.InnerHtml = s;
        }

        protected void Back_Click(object sender, EventArgs e)
        {
            Response.Redirect("CapNhatLH.aspx");
        }
    }
}